{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T03:28:20.805729Z",
     "start_time": "2021-10-17T03:28:20.530632Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T03:28:26.266788Z",
     "start_time": "2021-10-17T03:28:20.974275Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Checking whether there is an H2O instance running at http://localhost:54321 ..... not found.\n",
      "Attempting to start a local H2O server...\n",
      "  Java Version: java version \"1.8.0_11\"; Java(TM) SE Runtime Environment (build 1.8.0_11-b12); Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)\n",
      "  Starting server from /home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/backend/bin/h2o.jar\n",
      "  Ice root: /tmp/tmpg2cilmei\n",
      "  JVM stdout: /tmp/tmpg2cilmei/h2o_caihengxing_started_from_python.out\n",
      "  JVM stderr: /tmp/tmpg2cilmei/h2o_caihengxing_started_from_python.err\n",
      "  Server is running at http://127.0.0.1:54321\n",
      "Connecting to H2O server at http://127.0.0.1:54321 ... successful.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div style=\"overflow:auto\"><table style=\"width:50%\"><tr><td>H2O_cluster_uptime:</td>\n",
       "<td>02 secs</td></tr>\n",
       "<tr><td>H2O_cluster_timezone:</td>\n",
       "<td>Asia/Shanghai</td></tr>\n",
       "<tr><td>H2O_data_parsing_timezone:</td>\n",
       "<td>UTC</td></tr>\n",
       "<tr><td>H2O_cluster_version:</td>\n",
       "<td>3.32.1.5</td></tr>\n",
       "<tr><td>H2O_cluster_version_age:</td>\n",
       "<td>2 months and 12 days </td></tr>\n",
       "<tr><td>H2O_cluster_name:</td>\n",
       "<td>H2O_from_python_caihengxing_lz50xi</td></tr>\n",
       "<tr><td>H2O_cluster_total_nodes:</td>\n",
       "<td>1</td></tr>\n",
       "<tr><td>H2O_cluster_free_memory:</td>\n",
       "<td>26.67 Gb</td></tr>\n",
       "<tr><td>H2O_cluster_total_cores:</td>\n",
       "<td>40</td></tr>\n",
       "<tr><td>H2O_cluster_allowed_cores:</td>\n",
       "<td>40</td></tr>\n",
       "<tr><td>H2O_cluster_status:</td>\n",
       "<td>accepting new members, healthy</td></tr>\n",
       "<tr><td>H2O_connection_url:</td>\n",
       "<td>http://127.0.0.1:54321</td></tr>\n",
       "<tr><td>H2O_connection_proxy:</td>\n",
       "<td>{\"http\": null, \"https\": null}</td></tr>\n",
       "<tr><td>H2O_internal_security:</td>\n",
       "<td>False</td></tr>\n",
       "<tr><td>H2O_API_Extensions:</td>\n",
       "<td>Amazon S3, XGBoost, Algos, AutoML, Core V3, TargetEncoder, Core V4</td></tr>\n",
       "<tr><td>Python_version:</td>\n",
       "<td>3.7.3 final</td></tr></table></div>"
      ],
      "text/plain": [
       "--------------------------  ------------------------------------------------------------------\n",
       "H2O_cluster_uptime:         02 secs\n",
       "H2O_cluster_timezone:       Asia/Shanghai\n",
       "H2O_data_parsing_timezone:  UTC\n",
       "H2O_cluster_version:        3.32.1.5\n",
       "H2O_cluster_version_age:    2 months and 12 days\n",
       "H2O_cluster_name:           H2O_from_python_caihengxing_lz50xi\n",
       "H2O_cluster_total_nodes:    1\n",
       "H2O_cluster_free_memory:    26.67 Gb\n",
       "H2O_cluster_total_cores:    40\n",
       "H2O_cluster_allowed_cores:  40\n",
       "H2O_cluster_status:         accepting new members, healthy\n",
       "H2O_connection_url:         http://127.0.0.1:54321\n",
       "H2O_connection_proxy:       {\"http\": null, \"https\": null}\n",
       "H2O_internal_security:      False\n",
       "H2O_API_Extensions:         Amazon S3, XGBoost, Algos, AutoML, Core V3, TargetEncoder, Core V4\n",
       "Python_version:             3.7.3 final\n",
       "--------------------------  ------------------------------------------------------------------"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import h2o\n",
    "from h2o.automl import H2OAutoML\n",
    "h2o.init()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T03:28:30.754162Z",
     "start_time": "2021-10-17T03:28:30.749381Z"
    }
   },
   "outputs": [],
   "source": [
    "train_path = '../autox/data/allstate_claims/train.csv'\n",
    "test_path = '../autox/data/allstate_claims/test.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T03:28:41.628516Z",
     "start_time": "2021-10-17T03:28:32.012582Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Parse progress: |█████████████████████████████████████████████████████████| 100%\n",
      "Parse progress: |█████████████████████████████████████████████████████████| 100%\n"
     ]
    }
   ],
   "source": [
    "# Load data into H2O\n",
    "train = h2o.import_file(train_path)\n",
    "test  = h2o.import_file(test_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T03:28:41.973609Z",
     "start_time": "2021-10-17T03:28:41.706579Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead>\n",
       "<tr><th style=\"text-align: right;\">  id</th><th>cat1  </th><th>cat2  </th><th>cat3  </th><th>cat4  </th><th>cat5  </th><th>cat6  </th><th>cat7  </th><th>cat8  </th><th>cat9  </th><th>cat10  </th><th>cat11  </th><th>cat12  </th><th>cat13  </th><th>cat14  </th><th>cat15  </th><th>cat16  </th><th>cat17  </th><th>cat18  </th><th>cat19  </th><th>cat20  </th><th>cat21  </th><th>cat22  </th><th>cat23  </th><th>cat24  </th><th>cat25  </th><th>cat26  </th><th>cat27  </th><th>cat28  </th><th>cat29  </th><th>cat30  </th><th>cat31  </th><th>cat32  </th><th>cat33  </th><th>cat34  </th><th>cat35  </th><th>cat36  </th><th>cat37  </th><th>cat38  </th><th>cat39  </th><th>cat40  </th><th>cat41  </th><th>cat42  </th><th>cat43  </th><th>cat44  </th><th>cat45  </th><th>cat46  </th><th>cat47  </th><th>cat48  </th><th>cat49  </th><th>cat50  </th><th>cat51  </th><th>cat52  </th><th>cat53  </th><th>cat54  </th><th>cat55  </th><th>cat56  </th><th>cat57  </th><th>cat58  </th><th>cat59  </th><th>cat60  </th><th>cat61  </th><th>cat62  </th><th>cat63  </th><th>cat64  </th><th>cat65  </th><th>cat66  </th><th>cat67  </th><th>cat68  </th><th>cat69  </th><th>cat70  </th><th>cat71  </th><th>cat72  </th><th>cat73  </th><th>cat74  </th><th>cat75  </th><th>cat76  </th><th>cat77  </th><th>cat78  </th><th>cat79  </th><th>cat80  </th><th>cat81  </th><th>cat82  </th><th>cat83  </th><th>cat84  </th><th>cat85  </th><th>cat86  </th><th>cat87  </th><th>cat88  </th><th>cat89  </th><th>cat90  </th><th>cat91  </th><th>cat92  </th><th>cat93  </th><th>cat94  </th><th>cat95  </th><th>cat96  </th><th>cat97  </th><th>cat98  </th><th>cat99  </th><th>cat100  </th><th>cat101  </th><th>cat102  </th><th>cat103  </th><th>cat104  </th><th>cat105  </th><th>cat106  </th><th>cat107  </th><th>cat108  </th><th>cat109  </th><th>cat110  </th><th>cat111  </th><th>cat112  </th><th>cat113  </th><th>cat114  </th><th>cat115  </th><th>cat116  </th><th style=\"text-align: right;\">   cont1</th><th style=\"text-align: right;\">   cont2</th><th style=\"text-align: right;\">   cont3</th><th style=\"text-align: right;\">   cont4</th><th style=\"text-align: right;\">   cont5</th><th style=\"text-align: right;\">   cont6</th><th style=\"text-align: right;\">   cont7</th><th style=\"text-align: right;\">  cont8</th><th style=\"text-align: right;\">  cont9</th><th style=\"text-align: right;\">  cont10</th><th style=\"text-align: right;\">  cont11</th><th style=\"text-align: right;\">  cont12</th><th style=\"text-align: right;\">  cont13</th><th style=\"text-align: right;\">  cont14</th><th style=\"text-align: right;\">    loss</th></tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "<tr><td style=\"text-align: right;\">   1</td><td>A     </td><td>B     </td><td>A     </td><td>B     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>B     </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>D      </td><td>B      </td><td>B      </td><td>D      </td><td>D      </td><td>B      </td><td>D      </td><td>C      </td><td>B      </td><td>D      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>B      </td><td>C      </td><td>E      </td><td>A      </td><td>C      </td><td>T      </td><td>B       </td><td>G       </td><td>A       </td><td>A       </td><td>I       </td><td>E       </td><td>G       </td><td>J       </td><td>G       </td><td>BU      </td><td>BC      </td><td>C       </td><td>AS      </td><td>S       </td><td>A       </td><td>O       </td><td>LB      </td><td style=\"text-align: right;\">0.7263  </td><td style=\"text-align: right;\">0.245921</td><td style=\"text-align: right;\">0.187583</td><td style=\"text-align: right;\">0.789639</td><td style=\"text-align: right;\">0.310061</td><td style=\"text-align: right;\">0.718367</td><td style=\"text-align: right;\">0.33506 </td><td style=\"text-align: right;\">0.3026 </td><td style=\"text-align: right;\">0.67135</td><td style=\"text-align: right;\"> 0.8351 </td><td style=\"text-align: right;\">0.569745</td><td style=\"text-align: right;\">0.594646</td><td style=\"text-align: right;\">0.822493</td><td style=\"text-align: right;\">0.714843</td><td style=\"text-align: right;\"> 2213.18</td></tr>\n",
       "<tr><td style=\"text-align: right;\">   2</td><td>A     </td><td>B     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>B     </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>B      </td><td>B      </td><td>D      </td><td>D      </td><td>A      </td><td>B      </td><td>C      </td><td>B      </td><td>D      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>D      </td><td>C      </td><td>E      </td><td>E      </td><td>D      </td><td>T      </td><td>L       </td><td>F       </td><td>A       </td><td>A       </td><td>E       </td><td>E       </td><td>I       </td><td>K       </td><td>K       </td><td>BI      </td><td>CQ      </td><td>A       </td><td>AV      </td><td>BM      </td><td>A       </td><td>O       </td><td>DP      </td><td style=\"text-align: right;\">0.330514</td><td style=\"text-align: right;\">0.737068</td><td style=\"text-align: right;\">0.592681</td><td style=\"text-align: right;\">0.614134</td><td style=\"text-align: right;\">0.885834</td><td style=\"text-align: right;\">0.438917</td><td style=\"text-align: right;\">0.436585</td><td style=\"text-align: right;\">0.60087</td><td style=\"text-align: right;\">0.35127</td><td style=\"text-align: right;\"> 0.43919</td><td style=\"text-align: right;\">0.338312</td><td style=\"text-align: right;\">0.366307</td><td style=\"text-align: right;\">0.611431</td><td style=\"text-align: right;\">0.304496</td><td style=\"text-align: right;\"> 1283.6 </td></tr>\n",
       "<tr><td style=\"text-align: right;\">   5</td><td>A     </td><td>B     </td><td>A     </td><td>A     </td><td>B     </td><td>A     </td><td>A     </td><td>A     </td><td>B     </td><td>B      </td><td>B      </td><td>B      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>B      </td><td>B      </td><td>B      </td><td>D      </td><td>B      </td><td>D      </td><td>C      </td><td>B      </td><td>B      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>D      </td><td>C      </td><td>E      </td><td>E      </td><td>A      </td><td>D      </td><td>L       </td><td>O       </td><td>A       </td><td>B       </td><td>E       </td><td>F       </td><td>H       </td><td>F       </td><td>A       </td><td>AB      </td><td>DK      </td><td>A       </td><td>C       </td><td>AF      </td><td>A       </td><td>I       </td><td>GK      </td><td style=\"text-align: right;\">0.261841</td><td style=\"text-align: right;\">0.358319</td><td style=\"text-align: right;\">0.484196</td><td style=\"text-align: right;\">0.236924</td><td style=\"text-align: right;\">0.397069</td><td style=\"text-align: right;\">0.289648</td><td style=\"text-align: right;\">0.315545</td><td style=\"text-align: right;\">0.2732 </td><td style=\"text-align: right;\">0.26076</td><td style=\"text-align: right;\"> 0.32446</td><td style=\"text-align: right;\">0.381398</td><td style=\"text-align: right;\">0.373424</td><td style=\"text-align: right;\">0.195709</td><td style=\"text-align: right;\">0.774425</td><td style=\"text-align: right;\"> 3005.09</td></tr>\n",
       "<tr><td style=\"text-align: right;\">  10</td><td>B     </td><td>B     </td><td>A     </td><td>B     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>B     </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>B      </td><td>B      </td><td>D      </td><td>D      </td><td>D      </td><td>B      </td><td>C      </td><td>B      </td><td>D      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>D      </td><td>C      </td><td>E      </td><td>E      </td><td>D      </td><td>T      </td><td>I       </td><td>D       </td><td>A       </td><td>A       </td><td>E       </td><td>E       </td><td>I       </td><td>K       </td><td>K       </td><td>BI      </td><td>CS      </td><td>C       </td><td>N       </td><td>AE      </td><td>A       </td><td>O       </td><td>DJ      </td><td style=\"text-align: right;\">0.321594</td><td style=\"text-align: right;\">0.555782</td><td style=\"text-align: right;\">0.527991</td><td style=\"text-align: right;\">0.373816</td><td style=\"text-align: right;\">0.422268</td><td style=\"text-align: right;\">0.440945</td><td style=\"text-align: right;\">0.391128</td><td style=\"text-align: right;\">0.31796</td><td style=\"text-align: right;\">0.32128</td><td style=\"text-align: right;\"> 0.44467</td><td style=\"text-align: right;\">0.327915</td><td style=\"text-align: right;\">0.32157 </td><td style=\"text-align: right;\">0.605077</td><td style=\"text-align: right;\">0.602642</td><td style=\"text-align: right;\">  939.85</td></tr>\n",
       "<tr><td style=\"text-align: right;\">  11</td><td>A     </td><td>B     </td><td>A     </td><td>B     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>B     </td><td>B      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>B      </td><td>D      </td><td>B      </td><td>D      </td><td>B      </td><td>B      </td><td>C      </td><td>B      </td><td>B      </td><td>C      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>H      </td><td>D      </td><td>B      </td><td>D      </td><td>E      </td><td>E      </td><td>A      </td><td>P      </td><td>F       </td><td>J       </td><td>A       </td><td>A       </td><td>D       </td><td>E       </td><td>K       </td><td>G       </td><td>B       </td><td>H       </td><td>C       </td><td>C       </td><td>Y       </td><td>BM      </td><td>A       </td><td>K       </td><td>CK      </td><td style=\"text-align: right;\">0.273204</td><td style=\"text-align: right;\">0.15999 </td><td style=\"text-align: right;\">0.527991</td><td style=\"text-align: right;\">0.473202</td><td style=\"text-align: right;\">0.704268</td><td style=\"text-align: right;\">0.178193</td><td style=\"text-align: right;\">0.247408</td><td style=\"text-align: right;\">0.24564</td><td style=\"text-align: right;\">0.22089</td><td style=\"text-align: right;\"> 0.2123 </td><td style=\"text-align: right;\">0.204687</td><td style=\"text-align: right;\">0.202213</td><td style=\"text-align: right;\">0.246011</td><td style=\"text-align: right;\">0.432606</td><td style=\"text-align: right;\"> 2763.85</td></tr>\n",
       "<tr><td style=\"text-align: right;\">  13</td><td>A     </td><td>B     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>B     </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>B      </td><td>D      </td><td>B      </td><td>D      </td><td>B      </td><td>B      </td><td>C      </td><td>B      </td><td>B      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>D      </td><td>D      </td><td>E      </td><td>C      </td><td>A      </td><td>P      </td><td>J       </td><td>D       </td><td>A       </td><td>A       </td><td>E       </td><td>E       </td><td>H       </td><td>F       </td><td>B       </td><td>BI      </td><td>CS      </td><td>A       </td><td>AS      </td><td>AE      </td><td>A       </td><td>K       </td><td>DJ      </td><td style=\"text-align: right;\">0.54667 </td><td style=\"text-align: right;\">0.681761</td><td style=\"text-align: right;\">0.634224</td><td style=\"text-align: right;\">0.373816</td><td style=\"text-align: right;\">0.302678</td><td style=\"text-align: right;\">0.364464</td><td style=\"text-align: right;\">0.401162</td><td style=\"text-align: right;\">0.26847</td><td style=\"text-align: right;\">0.46226</td><td style=\"text-align: right;\"> 0.50556</td><td style=\"text-align: right;\">0.366788</td><td style=\"text-align: right;\">0.359249</td><td style=\"text-align: right;\">0.345247</td><td style=\"text-align: right;\">0.726792</td><td style=\"text-align: right;\"> 5142.87</td></tr>\n",
       "<tr><td style=\"text-align: right;\">  14</td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>B     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>B      </td><td>B      </td><td>D      </td><td>D      </td><td>B      </td><td>D      </td><td>C      </td><td>B      </td><td>B      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>D      </td><td>D      </td><td>E      </td><td>C      </td><td>A      </td><td>P      </td><td>J       </td><td>A       </td><td>A       </td><td>C       </td><td>E       </td><td>E       </td><td>H       </td><td>F       </td><td>B       </td><td>BI      </td><td>DK      </td><td>A       </td><td>J       </td><td>AF      </td><td>A       </td><td>K       </td><td>DJ      </td><td style=\"text-align: right;\">0.471447</td><td style=\"text-align: right;\">0.737068</td><td style=\"text-align: right;\">0.61366 </td><td style=\"text-align: right;\">0.189137</td><td style=\"text-align: right;\">0.295397</td><td style=\"text-align: right;\">0.381515</td><td style=\"text-align: right;\">0.363768</td><td style=\"text-align: right;\">0.24564</td><td style=\"text-align: right;\">0.40455</td><td style=\"text-align: right;\"> 0.47225</td><td style=\"text-align: right;\">0.334828</td><td style=\"text-align: right;\">0.352251</td><td style=\"text-align: right;\">0.342239</td><td style=\"text-align: right;\">0.382931</td><td style=\"text-align: right;\"> 1132.22</td></tr>\n",
       "<tr><td style=\"text-align: right;\">  20</td><td>A     </td><td>B     </td><td>A     </td><td>B     </td><td>A     </td><td>A     </td><td>A     </td><td>A     </td><td>B     </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>B      </td><td>D      </td><td>B      </td><td>D      </td><td>A      </td><td>B      </td><td>C      </td><td>B      </td><td>D      </td><td>C      </td><td>D      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>C      </td><td>B      </td><td>C      </td><td>E      </td><td>A      </td><td>C      </td><td>T      </td><td>H       </td><td>C       </td><td>A       </td><td>A       </td><td>K       </td><td>F       </td><td>F       </td><td>I       </td><td>G       </td><td>BI      </td><td>EB      </td><td>G       </td><td>AH      </td><td>Y       </td><td>A       </td><td>P       </td><td>LO      </td><td style=\"text-align: right;\">0.826591</td><td style=\"text-align: right;\">0.488789</td><td style=\"text-align: right;\">0.26357 </td><td style=\"text-align: right;\">0.62377 </td><td style=\"text-align: right;\">0.473767</td><td style=\"text-align: right;\">0.867021</td><td style=\"text-align: right;\">0.583389</td><td style=\"text-align: right;\">0.90267</td><td style=\"text-align: right;\">0.84847</td><td style=\"text-align: right;\"> 0.80218</td><td style=\"text-align: right;\">0.644013</td><td style=\"text-align: right;\">0.785706</td><td style=\"text-align: right;\">0.859764</td><td style=\"text-align: right;\">0.242416</td><td style=\"text-align: right;\"> 3585.75</td></tr>\n",
       "<tr><td style=\"text-align: right;\">  23</td><td>A     </td><td>B     </td><td>B     </td><td>B     </td><td>B     </td><td>A     </td><td>A     </td><td>A     </td><td>B     </td><td>B      </td><td>B      </td><td>B      </td><td>B      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>B      </td><td>D      </td><td>B      </td><td>B      </td><td>B      </td><td>B      </td><td>C      </td><td>B      </td><td>D      </td><td>D      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>D      </td><td>C      </td><td>C      </td><td>E      </td><td>C      </td><td>D      </td><td>T      </td><td>C       </td><td>Q       </td><td>A       </td><td>C       </td><td>H       </td><td>F       </td><td>G       </td><td>M       </td><td>K       </td><td>BI      </td><td>BC      </td><td>C       </td><td>K       </td><td>AX      </td><td>A       </td><td>Q       </td><td>IE      </td><td style=\"text-align: right;\">0.330514</td><td style=\"text-align: right;\">0.555782</td><td style=\"text-align: right;\">0.440642</td><td style=\"text-align: right;\">0.473202</td><td style=\"text-align: right;\">0.281143</td><td style=\"text-align: right;\">0.628534</td><td style=\"text-align: right;\">0.384099</td><td style=\"text-align: right;\">0.61229</td><td style=\"text-align: right;\">0.38249</td><td style=\"text-align: right;\"> 0.51111</td><td style=\"text-align: right;\">0.682315</td><td style=\"text-align: right;\">0.669033</td><td style=\"text-align: right;\">0.756454</td><td style=\"text-align: right;\">0.361191</td><td style=\"text-align: right;\">10280.2 </td></tr>\n",
       "<tr><td style=\"text-align: right;\">  24</td><td>A     </td><td>B     </td><td>A     </td><td>A     </td><td>B     </td><td>B     </td><td>A     </td><td>A     </td><td>B     </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>B      </td><td>B      </td><td>B      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>B      </td><td>A      </td><td>B      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>A      </td><td>D      </td><td>B      </td><td>B      </td><td>B      </td><td>B      </td><td>B      </td><td>B      </td><td>C      </td><td>B      </td><td>D      </td><td>C      </td><td>D      </td><td>A      </td><td>A      </td><td>B      </td><td>H      </td><td>D      </td><td>B      </td><td>C      </td><td>E      </td><td>A      </td><td>C      </td><td>T      </td><td>F       </td><td>D       </td><td>A       </td><td>F       </td><td>K       </td><td>H       </td><td>G       </td><td>J       </td><td>G       </td><td>BU      </td><td>DW      </td><td>A       </td><td>U       </td><td>S       </td><td>J       </td><td>O       </td><td>LY      </td><td style=\"text-align: right;\">0.7263  </td><td style=\"text-align: right;\">0.358319</td><td style=\"text-align: right;\">0.356819</td><td style=\"text-align: right;\">0.802892</td><td style=\"text-align: right;\">0.310061</td><td style=\"text-align: right;\">0.713343</td><td style=\"text-align: right;\">0.469223</td><td style=\"text-align: right;\">0.3026 </td><td style=\"text-align: right;\">0.67135</td><td style=\"text-align: right;\"> 0.8351 </td><td style=\"text-align: right;\">0.863052</td><td style=\"text-align: right;\">0.879347</td><td style=\"text-align: right;\">0.822493</td><td style=\"text-align: right;\">0.294523</td><td style=\"text-align: right;\"> 6184.59</td></tr>\n",
       "</tbody>\n",
       "</table>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": []
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T03:29:09.693034Z",
     "start_time": "2021-10-17T03:29:09.688472Z"
    }
   },
   "outputs": [],
   "source": [
    "y = \"loss\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T05:17:25.723744Z",
     "start_time": "2021-10-17T03:29:20.116673Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AutoML progress: |████████████████████████████████████████████████████████| 100%\n"
     ]
    }
   ],
   "source": [
    "aml2 = H2OAutoML(max_runtime_secs = 7200, seed = 1, project_name = \"allstate_claims\")\n",
    "aml2.train(y = y, training_frame = train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T05:17:32.544257Z",
     "start_time": "2021-10-17T05:17:25.842160Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stackedensemble prediction progress: |████████████████████████████████████| 100%\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat89' has levels not trained on: [\"F\"]\n",
      "  warnings.warn(w)\n",
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat92' has levels not trained on: [\"E\", \"G\"]\n",
      "  warnings.warn(w)\n",
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat96' has levels not trained on: [\"H\"]\n",
      "  warnings.warn(w)\n",
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat99' has levels not trained on: [\"U\"]\n",
      "  warnings.warn(w)\n",
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat103' has levels not trained on: [\"M\"]\n",
      "  warnings.warn(w)\n",
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat106' has levels not trained on: [\"Q\"]\n",
      "  warnings.warn(w)\n",
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat109' has levels not trained on: [\"AD\"]\n",
      "  warnings.warn(w)\n",
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat110' has levels not trained on: [\"BH\", \"CA\", \"EN\"]\n",
      "  warnings.warn(w)\n",
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat111' has levels not trained on: [\"L\"]\n",
      "  warnings.warn(w)\n",
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat113' has levels not trained on: [\"AA\", \"R\"]\n",
      "  warnings.warn(w)\n",
      "/home/caihengxing/anaconda3/lib/python3.7/site-packages/h2o/job.py:72: UserWarning: Test/Validation dataset column 'cat116' has levels not trained on: [\"A\", \"AI\", \"AQ\", \"BE\", \"BH\", \"BJ\", \"BN\", \"BR\", \"DB\", \"EM\", ...3 not listed..., \"FY\", \"HS\", \"IS\", \"IW\", \"JS\", \"KO\", \"LP\", \"LS\", \"MX\", \"N\"]\n",
      "  warnings.warn(w)\n"
     ]
    }
   ],
   "source": [
    "pred = aml2.predict(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T05:17:34.671148Z",
     "start_time": "2021-10-17T05:17:32.652127Z"
    }
   },
   "outputs": [],
   "source": [
    "sub = pd.read_csv(test_path)\n",
    "sub = sub[['id']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T05:17:35.040200Z",
     "start_time": "2021-10-17T05:17:34.795246Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "pred = h2o.as_list(pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T05:17:35.165460Z",
     "start_time": "2021-10-17T05:17:35.123867Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "sub[y] = pred['predict']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-17T05:17:35.700366Z",
     "start_time": "2021-10-17T05:17:35.247321Z"
    }
   },
   "outputs": [],
   "source": [
    "sub.to_csv(\"./h2o_sub_kaggle_allstate_claims.csv\", index = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
